package com.itHsuSE.demo5;

import java.util.Arrays;

/**
 * @author Hsu琛君珩
 * @version 1.0
 */
public class Test9 {
    public static void main(String[] args) {
        int[] weight = {1, 3, 4};
        int[] value = {15, 20, 30};
        int bagWeight = 4;
        int[] dp = new int[bagWeight + 1];
        /*for (int i = 0; i < weight.length; i++){ // 遍历物品
            for (int j = weight[i]; j <= bagWeight; j++){ // 遍历背包容量
                dp[j] = Math.max(dp[j], dp[j - weight[i]] + value[i]);
                System.out.println(Arrays.toString(dp));
            }
        }*/
        for (int j = 1; j <= bagWeight; j++){ // 遍历背包容量
            for (int i = 0; i < weight.length; i++){ // 遍历物品
                if (j - weight[i] >= 0){
                    dp[j] = Math.max(dp[j], dp[j - weight[i]] + value[i]);
                }
                System.out.println(Arrays.toString(dp));
            }
        }
        System.out.println();
    }
}
